local extension = Package:new("YS__yuansu", Package.CardPack)
extension.extensionName = "2333333"

Fk:loadTranslationTable{
  ["YS__yuansu"] = "○神-元素反应beta",
}

Fk:addDamageNature(328,"YS_water_damage",true)
Fk:addDamageNature(329,"YS_anemo_damage",false)
Fk:addDamageNature(330,"YS_geo_damage",false)
Fk:addDamageNature(331,"YS_grass_damage",false)
Fk:loadTranslationTable{
  ["YS_water_damage"] = "水元素",
  ["YS_anemo_damage"] = "风元素",
  ["YS_geo_damage"] = "岩元素",
  ["YS_grass_damage"] = "草元素",
}

extension:addCards{
  Fk:cloneCard("peach", Card.Diamond, 12),
  Fk:cloneCard("peach", Card.Heart, 4),
  Fk:cloneCard("peach", Card.Heart, 6),
  Fk:cloneCard("peach", Card.Diamond, 2),

  Fk:cloneCard("iron_chain", Card.Club, 10),
  Fk:cloneCard("iron_chain", Card.Club, 11),
  Fk:cloneCard("iron_chain", Card.Club, 12),
  Fk:cloneCard("iron_chain", Card.Club, 12),
}

local slash = Fk:cloneCard("slash")
local iceSlashSkill = fk.CreateActiveSkill{
  name = "ice__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = fk.IceDamage,
      skillName = self.name
    })
  end
}
local iceSlash = fk.CreateBasicCard{
  name = "ice__slash",
  skill = iceSlashSkill,
  is_damage_card = true,
}
extension:addCards{
  iceSlash:clone(Card.Spade, 7),
  iceSlash:clone(Card.Spade, 7),
  iceSlash:clone(Card.Spade, 8),
  iceSlash:clone(Card.Spade, 8),
}

local YS__waterSlashSkill = fk.CreateActiveSkill{
  name = "YS__water__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = 328, --水元素伤害
      skillName = self.name
    })
  end
}
Fk:addSkill(YS__waterSlashSkill)
local YS__water__slash = fk.CreateBasicCard{
    name = "YS__water__slash",
    skill = YS__waterSlashSkill,
    is_damage_card = true,
  }

extension:addCards({
   YS__water__slash:clone(Card.Spade, 2),
   YS__water__slash:clone(Card.Spade, 4), 
   YS__water__slash:clone(Card.Spade, 4), 
   YS__water__slash:clone(Card.Spade, 10),
   YS__water__slash:clone(Card.Club, 3),
   YS__water__slash:clone(Card.Club, 5),
   YS__water__slash:clone(Card.Club, 7),
   YS__water__slash:clone(Card.Club, 11),
   YS__water__slash:clone(Card.Spade, 4), 
   YS__water__slash:clone(Card.Spade, 10),
   YS__water__slash:clone(Card.Club, 3),
   YS__water__slash:clone(Card.Club, 5),
})
Fk:loadTranslationTable{
  ["YS__water__slash"] = "水杀",
  [":YS__water__slash"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：攻击范围内的一名角色<br/><b>效果</b>：对目标角色造成1点水属性伤害。",
}

local YS__AnemoSlashSkill = fk.CreateActiveSkill{
  name = "YS__Anemo__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = 329, --风元素伤害
      skillName = self.name
    })
  end
}
Fk:addSkill(YS__AnemoSlashSkill)
local YS__Anemo__slash = fk.CreateBasicCard{
    name = "YS__Anemo__slash",
    skill = YS__AnemoSlashSkill,
    is_damage_card = true,
  }
extension:addCards({
   YS__Anemo__slash:clone(Card.Diamond, 4), 
   YS__Anemo__slash:clone(Card.Club, 5),
   YS__Anemo__slash:clone(Card.Diamond, 4), 
   YS__Anemo__slash:clone(Card.Club, 5),
})
Fk:loadTranslationTable{
  ["YS__Anemo__slash"] = "风杀",
  [":YS__Anemo__slash"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：攻击范围内的一名角色<br/><b>效果</b>：对目标角色造成1点风属性伤害。（风属性伤害不能被传导）",
}

local YS__geoSlashSkill = fk.CreateActiveSkill{
  name = "YS__geo__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = 330, --岩元素伤害
      skillName = self.name
    })
  end
}
Fk:addSkill(YS__geoSlashSkill)
local YS__geo__slash = fk.CreateBasicCard{
    name = "YS__geo__slash",
    skill = YS__geoSlashSkill,
    is_damage_card = true,
  }
extension:addCards({
   YS__geo__slash:clone(Card.Spade, 2),
   YS__geo__slash:clone(Card.Heart, 4),
   YS__geo__slash:clone(Card.Spade, 2),
   YS__geo__slash:clone(Card.Heart, 4), 
})
Fk:loadTranslationTable{
  ["YS__geo__slash"] = "岩杀",
  [":YS__geo__slash"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：攻击范围内的一名角色<br/><b>效果</b>：对目标角色造成1点岩属性伤害。（岩属性伤害不能被传导）",
}

local YS__grassSlashSkill = fk.CreateActiveSkill{
  name = "YS__grass__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = 331, --草元素伤害
      skillName = self.name
    })
  end
}
Fk:addSkill(YS__grassSlashSkill)
local YS__grass__slash = fk.CreateBasicCard{
    name = "YS__grass__slash",
    skill = YS__grassSlashSkill,
    is_damage_card = true,
  }
extension:addCards({
   YS__grass__slash:clone(Card.Spade, 2),
   YS__grass__slash:clone(Card.Diamond, 4), 
   YS__grass__slash:clone(Card.Spade, 8),
   YS__grass__slash:clone(Card.Club, 5),
   YS__grass__slash:clone(Card.Spade, 2),
   YS__grass__slash:clone(Card.Diamond, 4), 
   YS__grass__slash:clone(Card.Spade, 8),
   YS__grass__slash:clone(Card.Club, 5),
})
Fk:loadTranslationTable{
  ["YS__grass__slash"] = "草杀",
  [":YS__grass__slash"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：攻击范围内的一名角色<br/><b>效果</b>：对目标角色造成1点草属性伤害。（草属性伤害不能被传导）",
}

local YS_water__jink_skill = fk.CreateActiveSkill{
  name = "YS_water__jink_skill",
  can_use = Util.FalseFunc,
  on_effect = function(self, room, effect)
    if effect.responseToEvent then
      effect.responseToEvent.isCancellOut = true
      local from = room:getPlayerById(effect.responseToEvent.from)
      local to = room:getPlayerById(effect.responseToEvent.to)
      if from:getMark("@!waterYS") == 0 then
        room:setPlayerMark(from, "@!waterYS", 1)
        room.logic:trigger("fk.YSelement", to, {dmg = {to = from, damage = 0}}) --无伤害附着
      end
    end
  end
}
local YS_water__jink = fk.CreateBasicCard{
  name = "YS_water__jink",
  skill = YS_water__jink_skill,
  is_passive = true,
}
extension:addCards({
  YS_water__jink:clone(Card.Heart, 2),
  YS_water__jink:clone(Card.Heart, 12),
  YS_water__jink:clone(Card.Diamond, 3),
  YS_water__jink:clone(Card.Diamond, 4),
  YS_water__jink:clone(Card.Diamond, 5),
  YS_water__jink:clone(Card.Diamond, 6),
})
Fk:loadTranslationTable{
  ["YS_water__jink"] = "水闪",
  [":YS_water__jink"] = "基本牌<br/><b>时机</b>：【杀】对你生效时<br/><b>目标</b>：此【杀】<br/><b>效果</b>：抵消此【杀】效果并令对方产生水附着。",
}

local YS_ice__jink_skill = fk.CreateActiveSkill{
  name = "YS_ice__jink_skill",
  can_use = Util.FalseFunc,
  on_effect = function(self, room, effect)
    if effect.responseToEvent then
      effect.responseToEvent.isCancellOut = true
      local from = room:getPlayerById(effect.responseToEvent.from)
      local to = room:getPlayerById(effect.responseToEvent.to)
      if from:getMark("@!iceYS") == 0 then
        room:setPlayerMark(from, "@!iceYS", 1)
        room.logic:trigger("fk.YSelement", to, {dmg = {to = from, damage = 0}}) --无伤害附着
      end
    end
  end
}
local YS_ice__jink = fk.CreateBasicCard{
  name = "YS_ice__jink",
  skill = YS_ice__jink_skill,
  is_passive = true,
}
extension:addCards({
  YS_ice__jink:clone(Card.Spade, 2),
  YS_ice__jink:clone(Card.Spade, 12),
  YS_ice__jink:clone(Card.Club, 3),
  YS_ice__jink:clone(Card.Club, 4),
  YS_ice__jink:clone(Card.Club, 5),
  YS_ice__jink:clone(Card.Club, 6),
})
Fk:loadTranslationTable{
  ["YS_ice__jink"] = "冰闪",
  [":YS_ice__jink"] = "基本牌<br/><b>时机</b>：【杀】对你生效时<br/><b>目标</b>：此【杀】<br/><b>效果</b>：抵消此【杀】效果并令对方产生冰附着。",
}




local YS__element = fk.CreateTriggerSkill{
  name = "YS__element",
  frequency = Skill.Compulsory,
  mute = true,
  priority = -1,
  events = {fk.DamageInflicted,"fk.YSelement"},
  can_trigger = function(self, event, target, player, data)
    local YS_generals = {}
    for _, g in pairs(Fk.generals) do
      local p = g.package.name
      if p == "YS__liyue" or p == "YS__fontaine" or p == "YS__fontaine" or p == "YS__sumeru" or p == "YS__mondstadt" or p == "YS__inazima" then
        table.insert(YS_generals, g.name)
      end
    end
    if event == fk.DamageInflicted then
      if data.from then
        return data.from == player and data.damage and data.damageType ~= 1 and data.to and not data.to.dead and  --有来源
      (not table.contains(player.room.disabled_packs, "YS__yuansu") or table.contains(YS_generals, player.general))
      else
        return data.damage and data.damageType ~= 1 and data.to and not data.to.dead and data.to == player and  --无来源就受伤的人自己触发
        (not table.contains(player.room.disabled_packs, "YS__yuansu") or table.contains(YS_generals, player.general))
      end
    elseif event == "fk.YSelement" then
      return target == player and not player.dead
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then --predamage时机太靠前了，会先于转化类，但是又要在伤害发生前才行
    local to = data.to
    local num = 1
    if data.damageType == 3 and to:getMark("@!fireYS") == 0 then
      room:setPlayerMark(to, "@!fireYS", num)
      room.logic:trigger("fk.YSelement", player, {dmg = data}) --触发了附着 可能触发某些技能
    elseif data.damageType == 2 and to:getMark("@!thunderYS") == 0 then
      room:setPlayerMark(to, "@!thunderYS", num)
      room.logic:trigger("fk.YSelement", player, {dmg = data})
    elseif data.damageType == 4 and to:getMark("@!iceYS") == 0 then
      room:setPlayerMark(to, "@!iceYS", num)
      room.logic:trigger("fk.YSelement", player, {dmg = data})
    elseif data.damageType == 328 and to:getMark("@!waterYS") == 0 then
      room:setPlayerMark(to, "@!waterYS", num)
      room.logic:trigger("fk.YSelement", player, {dmg = data})
    elseif data.damageType == 329 and (to:getMark("@!waterYS") ~= 0 or to:getMark("@!fireYS") ~= 0 or to:getMark("@!thunderYS") ~= 0 or to:getMark("@!iceYS") ~= 0) then
      room.logic:trigger("fk.YSelement", player, {dmg = data})
    elseif data.damageType == 330 and (to:getMark("@!waterYS") ~= 0 or to:getMark("@!fireYS") ~= 0 or to:getMark("@!thunderYS") ~= 0 or to:getMark("@!iceYS") ~= 0) then
      room.logic:trigger("fk.YSelement", player, {dmg = data})
    elseif data.damageType == 331 and to:getMark("@!grassYS") == 0 then
      room:setPlayerMark(to, "@!grassYS", num)
      room.logic:trigger("fk.YSelement", player, {dmg = data})
    end
    elseif event == "fk.YSelement" then
      local to = data.dmg.to
    if data.dmg and (to:getMark("@!waterYS") ~= 0 or to:getMark("@!fireYS") ~= 0 or to:getMark("@!thunderYS") ~= 0 or to:getMark("@!iceYS") ~= 0) and (data.dmg.damageType == 329 or data.dmg.damageType == 330) then
      if data.dmg.damageType == 329 then
        room.logic:trigger("fk.YS__Swirl", player, {n = data})
        room:notifySkillInvoked(to,"YS__Swirl","negative")
        room:sendLog{
          type = "#SwirlRaction",
          from = player.id,
          to = { to.id },
        }
        room:damage{
          from = player,
          to = to,
          damage = 1,
          damageType = 1,
          isVirtualDMG = true,
          skillName = "YS_halfdamage",
          YS_halfdamage = true,
        }
        local next = to:getNextAlive()
        local last = to:getLastAlive()
        local num = 1
        if to:getMark("@!fireYS") ~= 0 then
          room:setPlayerMark(to, "@!fireYS", 0)
          if next:getMark("@!fireYS") == 0 then
            room:setPlayerMark(next, "@!fireYS", num)
            room.logic:trigger("fk.YSelement", player, {dmg = {to = next, damage = 0}})
          end
          if last:getMark("@!fireYS") == 0 then
            room:setPlayerMark(last, "@!fireYS", num)
            room.logic:trigger("fk.YSelement", player, {dmg = {to = last, damage = 0}})
          end
        end
        if to:getMark("@!iceYS") ~= 0 then
          room:setPlayerMark(to, "@!iceYS", 0)
          if next:getMark("@!iceYS") == 0 then
            room:setPlayerMark(next, "@!iceYS", num)
            room.logic:trigger("fk.YSelement", player, {dmg = {to = next, damage = 0}})
          end
          if last:getMark("@!iceYS") == 0 then
            room:setPlayerMark(last, "@!iceYS", num)
            room.logic:trigger("fk.YSelement", player, {dmg = {to = last, damage = 0}})
          end
        end
        if to:getMark("@!waterYS") ~= 0 then
          room:setPlayerMark(to, "@!waterYS", 0)
          if next:getMark("@!waterYS") == 0 then
            room:setPlayerMark(next, "@!waterYS", num)
            room.logic:trigger("fk.YSelement", player, {dmg = {to = next, damage = 0}})
          end
          if last:getMark("@!waterYS") == 0 then
            room:setPlayerMark(last, "@!waterYS", num)
            room.logic:trigger("fk.YSelement", player, {dmg = {to = last, damage = 0}})
          end
        end
        if to:getMark("@!thunderYS") ~= 0 then
          room:setPlayerMark(to, "@!thunderYS", 0)
          if next:getMark("@!thunderYS") == 0 then
            room:setPlayerMark(next, "@!thunderYS", num)
            room.logic:trigger("fk.YSelement", player, {dmg = {to = next, damage = 0}})
          end
          if last:getMark("@!thunderYS") == 0 then
            room:setPlayerMark(last, "@!thunderYS", num)
            room.logic:trigger("fk.YSelement", player, {dmg = {to = last, damage = 0}})
          end
        end
        elseif data.dmg.damageType == 330 then
        room:setPlayerMark(to,"@!fireYS",0)
        room:setPlayerMark(to,"@!iceYS",0)
        room:setPlayerMark(to,"@!thunderYS",0)
        room:setPlayerMark(to,"@!waterYS",0)
        room.logic:trigger("fk.YS__Crystallize", player, {n = data})
        room:notifySkillInvoked(to,"YS__Crystallize","special")
        room:sendLog{
          type = "#CrystallizeRaction",
          from = player.id,
          to = { to.id },
        }
        room:changeShield(player,1)
        end
      elseif data.dmg and to:getMark("@!fireYS") ~= 0 and to:getMark("@!waterYS") ~= 0 then
        room:setPlayerMark(to, "@!fireYS", 0)
        room:setPlayerMark(to, "@!waterYS", 0)
        room.logic:trigger("fk.YS__Vaporize", player, {n = data}) --触发了XX反应 可能触发某些技能
        room:notifySkillInvoked(to,"YS__Vaporize","drawcard")
        room:sendLog{
          type = "#VaporizeRaction",
          from = player.id,
          to = { to.id },
        }
        if to.id < 0 then
          data.dmg.damage = 2*data.dmg.damage
        else
          data.dmg.damage = data.dmg.damage + 1
        end
      elseif data.dmg and to:getMark("@!fireYS") ~= 0 and to:getMark("@!iceYS") ~= 0 then
        room:setPlayerMark(to, "@!fireYS", 0)
        room:setPlayerMark(to, "@!iceYS", 0)
        room.logic:trigger("fk.YS__Melt", player, {n = data})
        room:notifySkillInvoked(to,"YS__Melt","drawcard")
        room:sendLog{
          type = "#MeltRaction",
          from = player.id,
          to = { to.id },
        }
        if to.id < 0 then
          data.dmg.damage = 2*data.dmg.damage
        else
          data.dmg.damage = data.dmg.damage + 1
        end
      elseif data.dmg and to:getMark("@!waterYS") ~= 0 and to:getMark("@!iceYS") ~= 0 then
        room:setPlayerMark(to, "@!waterYS", 0)
        room:setPlayerMark(to, "@!iceYS", 0)
        room.logic:trigger("fk.YS__Frozen", player, {n = data})
        room:notifySkillInvoked(to,"YS__Frozen","defensive")
        room:sendLog{
          type = "#FrozenRaction",
          from = player.id,
          to = { to.id },
        }
        if to.id < 0 then
          room:setPlayerMark(to,"@@YS__Frozen",1)
        else
          room:setPlayerMark(to,"@@YS__Frozen-turn",1)
        end
      elseif data.dmg and to:getMark("@!thunderYS") ~= 0 and to:getMark("@!fireYS") ~= 0 then
        room:setPlayerMark(to, "@!thunderYS", 0)
        room:setPlayerMark(to, "@!fireYS", 0)
        room.logic:trigger("fk.YS__Overloaded", player, {n = data})
        room:notifySkillInvoked(to,"YS__Overloaded","drawcard")
      if to.id < 0 then
        if to.faceup then
          room:sendLog{
            type = "#OverloadedRactionA",
            from = player.id,
            to = { to.id },
          }
          to:turnOver()
        else
          room:sendLog{
            type = "#OverloadedRactionB",
            from = player.id,
            to = { to.id },
          }
          data.dmg.damage = data.dmg.damage + 1
        end  
      else
        if to:getNextAlive(true) ~= room.current and to ~= room.current then
        room:sendLog{
          type = "#OverloadedRactionA",
          from = player.id,
          to = { to.id },
        }
        room:sendLog{
          type = "#OverloadedRactiona",
          from = to.id,
          to = { to:getNextAlive(true).id },
        }
        room:swapSeat(to, to:getNextAlive())
        else
          room:sendLog{
            type = "#OverloadedRactionB",
            from = player.id,
            to = { to.id },
          }
          data.dmg.damage = data.dmg.damage + 1
        end
      end
      elseif data.dmg and to:getMark("@!thunderYS") ~= 0 and to:getMark("@!waterYS") ~= 0 then
        room:setPlayerMark(to, "@!thunderYS", 0)
        room:setPlayerMark(to, "@!waterYS", 0)
        room.logic:trigger("fk.YS__ElectroCharged", player, {n = data})
        room:notifySkillInvoked(to,"YS__ElectroCharged","special")
        room:sendLog{
          type = "#ElectroChargedRaction",
          from = player.id,
          to = { to.id },
        }
        room:damage{
          from = player,
          to = to,
          damage = 1,
          isVirtualDMG = true,
          skillName = "YS_halfdamage",
          YS_halfdamage = true,
        }
        if to:getLastAlive() ~= room.current then
          room:damage{
            from = player,
            to = to:getLastAlive(),
            damage = 1,
            isVirtualDMG = true,
            skillName = "YS_halfdamage",
            YS_halfdamage = true,
          }
        end
        if to:getNextAlive() ~= room.current then
          room:damage{
            from = player,
            to = to:getNextAlive(),
            damage = 1,
            isVirtualDMG = true,
            skillName = "YS_halfdamage",
            YS_halfdamage = true,
          }
        end
      elseif data.dmg and to:getMark("@!thunderYS") ~= 0 and to:getMark("@!iceYS") ~= 0 then
        room:setPlayerMark(to, "@!thunderYS", 0)
        room:setPlayerMark(to, "@!iceYS", 0)
        room.logic:trigger("fk.YS__Superconduct", player, {n = data})
        room:notifySkillInvoked(to,"YS__Superconduct","special")
        room:sendLog{
          type = "#SuperconductRaction",
          from = player.id,
          to = { to.id },
        }
        room:damage{
          from = player,
          to = to,
          damage = 1,
          isVirtualDMG = true,
          skillName = "YS_halfdamage",
          YS_halfdamage = true,
        }
        if to:getLastAlive() ~= room.current then
          room:damage{
            from = player,
            to = to:getLastAlive(),
            damage = 1,
            isVirtualDMG = true,
            skillName = "YS_halfdamage",
            YS_halfdamage = true,
          }
        end
        if to:getNextAlive() ~= room.current then
          room:damage{
            from = player,
            to = to:getNextAlive(),
            damage = 1,
            isVirtualDMG = true,
            skillName = "YS_halfdamage",
            YS_halfdamage = true,
          }
        end
      elseif data.dmg and to:getMark("@!grassYS") ~= 0 and to:getMark("@!fireYS") ~= 0 then
        room:setPlayerMark(to, "@!fireYS", 0)
        room:setPlayerMark(to, "@!grassYS", 0)
        room.logic:trigger("fk.YS__Burning", player, {n = data})
        room:notifySkillInvoked(to,"YS__Burning","offensive")
        room:sendLog{
          type = "#BurningRaction",
          from = player.id,
          to = { to.id },
        }
        room:addPlayerMark(to,"@YS__Burning",2)
      elseif data.dmg and to:getMark("@!grassYS") ~= 0 and to:getMark("@!thunderYS") ~= 0 then
        room:setPlayerMark(to, "@!grassYS", 0)
        room:setPlayerMark(to, "@!thunderYS", 0)
        room.logic:trigger("fk.YS__Quicken", player, {n = data})
        room:notifySkillInvoked(to,"YS__Quicken","control")
        room:sendLog{
          type = "#QuickenRaction",
          from = player.id,
          to = { to.id },
        }
        player:drawCards(1)
        room:addPlayerMark(player,"@!YS__Quicken",2)
      elseif data.dmg and to:getMark("@!grassYS") ~= 0 and to:getMark("@!waterYS") ~= 0 then
        room:setPlayerMark(to, "@!grassYS", 0)
        room:setPlayerMark(to, "@!waterYS", 0)
        room.logic:trigger("fk.YS__BLOOM", player, {n = data})
        room:notifySkillInvoked(to,"YS__BLOOM","support")
        room:sendLog{
          type = "#BloomRaction",
          from = player.id,
          to = { to.id },
        }
        room:addPlayerMark(to,"@!YS__seed",1)
      end
    end
  end,
}
Fk:loadTranslationTable{
  ["@@YS__Frozen-turn"] = "<font color='#95CACA'>██冻结███</font>",
  ["@@YS__Frozen"] = "<font color='#95CACA'>██冻结███</font>",
  ["@YS__Burning"] = "<font color='red'>【燃烧】</font>",
  ["#VaporizeRaction"] = "%from 对 %to 触发了蒸发反应，造成的伤害增加！",
  ["#MeltRaction"] = "%from 对 %to 触发了融化反应，造成的伤害增加！",
  ["#FrozenRaction"] = "%from 对 %to 触发了冻结反应，%to 被冻结了！",
  ["#ShatteredRaction"] = "%from 对 %to 触发了碎冰反应，造成的伤害增加且 %to 解除了冻结！",
  ["#OverloadedRactionA"] = "%from 对 %to 触发了超载反应！",
  ["#OverloadedRactiona"] = "%from 与 %to 交换了位置！",
  ["#OverloadedRactionB"] = "%from 对 %to 触发了超载反应，造成的伤害增加！",
  ["#ElectroChargedRaction"] = "%from 对 %to 触发了感电反应！",
  ["#SuperconductRaction"] = "%from 对 %to 触发了超导反应！",
  ["#BurningRaction"] = "%from 对 %to 触发了燃烧反应，%to 烧起来了！",
  ["#QuickenRaction"] = "%from 对 %to 触发了激化反应，%from 生成了激化领域！",
  ["#BloomRaction"] = "%from 对 %to 触发了绽放反应，%to 获得了草原核！",
  ["#SEEDBOOM"] = "%from 的草原核爆炸了, %from 本回合手牌上限-%arg",
  ["#CrystallizeRaction"] = "%from 对 %to 触发了结晶反应！",
  ["#SwirlRaction"] = "%from 对 %to 触发了扩散反应！",
  ["#YS__frozen_prohibit"] = "冻结",
  ["#YS__frozen"] = "冻结",
  ["#YS__burning"] = "燃烧",
  ["#YS__quicken"] = "激化",
  ["YS__aggravate"] = "超激化",
  ["YS__spread"] = "蔓激化",
  ["YS__hyperbloom"] = "超绽放",
  ["YS__burgeon"] = "烈绽放",
  ["YS__Frozen"] = "冻结",
  ["YS__Shattered"] = "碎冰",
  ["YS__Melt"] = "融化",
  ["YS__Superconduct"] = "超导",
  ["YS__Overloaded"] = "超载",
  ["YS__Vaporize"] = "蒸发",
  ["YS__ElectroCharged"] = "感电",
  ["YS__Burning"] = "燃烧",
  ["YS__Quicken"] = "激化",
  ["YS__BLOOM"] = "绽放",
  ["#YS__SEED"] = "草原核",
  ["YS__Crystallize"] = "结晶",
  ["YS__Swirl"] = "扩散",
  ["@YS_halfdamage"] = "【裂痕】",
  ["#YS__halfdamage"] = "裂伤",
}
Fk:addSkill(YS__element)

local YS__frozen = fk.CreateTriggerSkill{
  name = "#YS__frozen",
  frequency = Skill.Compulsory,
  priority = 0,
  events = {fk.DamageInflicted, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return target == player and (player:getMark("@@YS__Frozen-turn") ~= 0 or player:getMark("@@YS__Frozen") ~= 0) and data.damage and (data.damageType == fk.NormalDamage or data.damageType == fk.FireDamage)
    else
      return target == player and player:getMark("@@YS__Frozen") ~= 0
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      room.logic:trigger("fk.YS__Shattered", player, {n = data})
      room:notifySkillInvoked(player,"YS__Shattered","negative")
      room:sendLog{
        type = "#ShatteredRaction",
        from = data.from.id,
        to = { data.to.id },
      }
      player.room:setPlayerMark(player, "@@YS__Frozen-turn", 0)
      player.room:setPlayerMark(player, "@@YS__Frozen", 0)
      if target.id < 0 then
        data.damage = 2*data.damage
      else
        data.damage = data.damage + 1
      end
    else
      player.room:setPlayerMark(player, "@@YS__Frozen", 0)
    end
  end,
}
local YS__frozen_prohibit = fk.CreateProhibitSkill{
  name = "#YS__frozen_prohibit",
  global = true,
  prohibit_use = function(self, player, card)
    return player:getMark("@@YS__Frozen-turn") > 0 or player:getMark("@@YS__Frozen") > 0
  end,
  prohibit_response = function(self, player, card)
    return player:getMark("@@YS__Frozen-turn") > 0 or player:getMark("@@YS__Frozen") > 0
  end,
}
local YS__frozen_valid = fk.CreateInvaliditySkill {
  name = "#YS__frozen_valid",
  global = true,
  invalidity_func = function(self, from, skill)
    return (from:getMark("@@YS__Frozen-turn") ~= 0 or from:getMark("@@YS__Frozen") ~= 0)
    and not (skill:isEquipmentSkill() or skill.name:endsWith("&"))
  end
}
Fk:addSkill(YS__frozen)
Fk:addSkill(YS__frozen_prohibit)
Fk:addSkill(YS__frozen_valid)

local YS__burning = fk.CreateTriggerSkill{
  name = "#YS__burning",
  frequency = Skill.Compulsory,
  priority = 0,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@YS__Burning") ~= 0
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player,"YS__Burning","offensive")
    room:addPlayerMark(player, "@YS__Burning", -1)
    local Ecards = table.filter(player:getCardIds("e"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
    local Hcards = table.filter(player:getCardIds("h"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
    if #Ecards > 0 then 
      room:throwCard(table.random(Ecards, 1), self.name, player, player)
    else
      room:throwCard(table.random(Hcards, 1), self.name, player, player)
    end
    if player:getMark("@!fireYS") == 0 then
      room:setPlayerMark(player, "@!fireYS", 1)
      room.logic:trigger("fk.YSelement", player, {dmg = {to = player, damage = 0}}) --无伤害附着就这样吧。。
    end
  end,
}
Fk:addSkill(YS__burning)


local YS__quicken = fk.CreateTriggerSkill{
  name = "#YS__quicken",
  frequency = Skill.Compulsory,
  priority = 0,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@!YS__Quicken") ~= 0 and data.damage and (data.damageType == 331 or data.damageType == 2)
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    if data.damageType == 2 then
      room:notifySkillInvoked(player,"YS__aggravate","masochism")
      player:drawCards(1,"YS__aggravate")
    else
      room:notifySkillInvoked(player,"YS__spread","support")
      player:drawCards(1,"YS__spread")
    end
    room:addPlayerMark(player, "@!YS__Quicken", -1)
  end,
}
Fk:addSkill(YS__quicken)

local YS__SEED = fk.CreateTriggerSkill{
  name = "#YS__SEED",
  frequency = Skill.Compulsory,
  priority = 0,
  events = {fk.EventPhaseStart,fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player:getMark("@!YS__seed") ~= 0 and target == player and player.phase == Player.Discard
    else
      return player:getMark("@!YS__seed") ~= 0 and target == player and data.damage and (data.damageType == 3 or data.damageType == 2)
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
    room:notifySkillInvoked(player,"YS__BLOOM","support")
    room:sendLog{
      type = "#SEEDBOOM",
      from = player.id,
      arg = player:getMark("@!YS__seed"),
    }
    room:addPlayerMark(player, MarkEnum.MinusMaxCardsInTurn, player:getMark("@!YS__seed"))
    room:setPlayerMark(player, "@!YS__seed", 0)
    if player:getMark("@!grassYS") == 0 then
      room:setPlayerMark(player, "@!grassYS", 1)
      room.logic:trigger("fk.YSelement", player, {dmg = {to = player, damage = 0}})
    end
    else
      if data.damageType == 2 then
        room:notifySkillInvoked(player,"YS__hyperbloom","special")
        room:damage{
          from = data.from,
          to = data.to,
          damage = player:getMark("@!YS__seed"),
          damageType = 331,
          skillName = self.name,
        }
        room:setPlayerMark(player, "@!YS__seed", 0)
      else
        room:notifySkillInvoked(player,"YS__burgeon","offensive")
        room:damage{
          from = data.from,
          to = data.to,
          damage = player:getMark("@!YS__seed"),
          damageType = 331,
          skillName = self.name,
        }
        room:setPlayerMark(player, "@!YS__seed", 0)
      end
    end
  end,
}
Fk:addSkill(YS__SEED)

local YS__halfdamage = fk.CreateTriggerSkill{
  name = "YS__halfdamage",
  frequency = Skill.Compulsory,
  priority = 0.1,
  events = {fk.DamageInflicted, fk.Damaged, fk.HpRecover},
  can_trigger = function(self, event, target, player, data)
  if event == fk.HpRecover then
    return target == player and player:getMark("@YS_halfdamage") ~= 0
  else
    return target == player and (data.YS_halfdamage or data.skillName == "YS_halfdamage")
  end
  end,
  on_trigger = function(self, event, target, player, data)
  local room = player.room
  if event == fk.Damaged then
    room:addPlayerMark(player, "@YS_halfdamage", 1)
    if player:getMark("@YS_halfdamage") == 2 then
      room:setPlayerMark(player, "@YS_halfdamage", 0)
      if player.hp > 0 then
      room:loseHp(player,1, self.name)
      end
    end
  elseif event == fk.DamageInflicted then
    if data.chain then data.isVirtualDMG = true end
  elseif event == fk.HpRecover then
    room:setPlayerMark(player, "@YS_halfdamage", 0)
  end
  end,
}
Fk:addSkill(YS__halfdamage)

local yuansu_rule = fk.CreateTriggerSkill{
  name = "#yuansu_rule",
  priority = 0.001,
  global = true,

  refresh_events = {fk.GamePrepared},
  can_refresh = function(self, event, target, player, data)
    return not table.contains(player.room.disabled_packs, "YS__yuansu")
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room.logic:addTriggerSkill(YS__element)
    room.logic:addTriggerSkill(YS__frozen)
    room.logic:addTriggerSkill(YS__burning)
    room.logic:addTriggerSkill(YS__SEED)
    room.logic:addTriggerSkill(YS__halfdamage)
    room.logic:addTriggerSkill(YS__quicken)
  end,
}
Fk:addSkill(yuansu_rule)

return extension